import re

# []集合
# [abc] 匹配 a, b, c 中的任意一个字符
ret = re.search("[abc]x", "ax")
"<re.Match object; span=(0, 2), match='ax'>"
ret = re.search("[abc]x", "bx")
"<re.Match object; span=(0, 2), match='bx'>"
ret = re.search("[abc]x", "cx")
"<re.Match object; span=(0, 2), match='cx'>"

# [0-9]
ret = re.search("a[0-9]b", "a2bcc")
"<re.Match object; span=(0, 3), match='a2b'>"
# [a-z]
ret = re.search("1[a-z]2", "1v2")
"<re.Match object; span=(0, 3), match='1v2'>"
# [A-Z]
ret = re.search("1[A-Z]2", "1V2")
"<re.Match object; span=(0, 3), match='1V2'>"

# | 或匹配
# a|b , 匹配 a 或者 b
ret = re.search("a|b", "abc")
"<re.Match object; span=(0, 1), match='a'>"
ret = re.search("a|b", "bcd")
"<re.Match object; span=(0, 1), match='b'>"

# () 组合，将括号中内容看成一个整体
# (ab)cd, 匹配 abcd
ret = re.search("(ab)cd", "abcdef")
"<re.Match object; span=(0, 4), match='abcd'>"
ret = re.search("(ab)|(cd)", "cdef")
"<re.Match object; span=(0, 2), match='cd'>"

print(ret)
